﻿using System.Web.Routing;

namespace Kratos.Framework.Routing
{
    /// <summary>
    /// 自定义小写Route
    /// </summary>
    public class LowerCaseRoute : Route
    {
        public LowerCaseRoute(string url, IRouteHandler routeHandler)
            : base(url, routeHandler) { }

        public LowerCaseRoute(string url, RouteValueDictionary defaults, IRouteHandler routeHandler)
            : base(url, defaults, routeHandler) { }

        public LowerCaseRoute(string url, RouteValueDictionary defaults, RouteValueDictionary constraints, IRouteHandler routeHandler)
            : base(url, defaults, constraints, routeHandler) { }

        public LowerCaseRoute(string url, RouteValueDictionary defaults, RouteValueDictionary constraints, RouteValueDictionary dataTokens, IRouteHandler routeHandler)
            : base(url, defaults, constraints, dataTokens, routeHandler) { }

        public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
        {
            var virtualPathData = base.GetVirtualPath(requestContext, values);
            if (virtualPathData != null)
            {
                virtualPathData.VirtualPath = virtualPathData.VirtualPath.ToLowerInvariant();
            }

            return virtualPathData;
        }
    }
}
